package com.sinodata.bsm.cicp.util;

import java.io.Serializable;

/**
 * 封装了一个文件的属性
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author wangmh
 * @version 1.0
 */
public final class FileAttribute implements Serializable {
    private static final long serialVersionUID = -6568231115758510724L;
    public String name;
    public String mode;
    public int linkNumber;
    public String owner;
    public String group;
    public long size;
    public long lastTime;
    public String lastModification;

    public FileAttribute() {

    }

    /**
     * @param name
     * @param mode
     * @param linkNumber
     * @param owner
     * @param group
     * @param size
     * @param lastTime
     * @param lastModification
     */
    public FileAttribute(String name, String mode, int linkNumber, String owner, String group, long size, long lastTime, String lastModification) {
        super();
        this.name = name;
        this.mode = mode;
        this.linkNumber = linkNumber;
        this.owner = owner;
        this.group = group;
        this.size = size;
        this.lastTime = lastTime;
        this.lastModification = lastModification;
    }

    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer();
        sb.append(mode).append(" ").append(linkNumber).append(" ").append(owner).append(" ").append(group).append(" ").append(size).append(" ").append(lastModification).append(" ").append(name).append(" ").append(lastTime);
        return sb.toString();
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((group == null) ? 0 : group.hashCode());
        result = prime * result + ((lastModification == null) ? 0 : lastModification.hashCode());
        result = prime * result + (int) (lastTime ^ (lastTime >>> 32));
        result = prime * result + linkNumber;
        result = prime * result + ((mode == null) ? 0 : mode.hashCode());
        result = prime * result + ((name == null) ? 0 : name.hashCode());
        result = prime * result + ((owner == null) ? 0 : owner.hashCode());
        result = prime * result + (int) (size ^ (size >>> 32));
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        FileAttribute other = (FileAttribute) obj;
        if (group == null) {
            if (other.group != null)
                return false;
        } else if (!group.equals(other.group))
            return false;
        if (lastModification == null) {
            if (other.lastModification != null)
                return false;
        } else if (!lastModification.equals(other.lastModification))
            return false;
        if (lastTime != other.lastTime)
            return false;
        if (linkNumber != other.linkNumber)
            return false;
        if (mode == null) {
            if (other.mode != null)
                return false;
        } else if (!mode.equals(other.mode))
            return false;
        if (name == null) {
            if (other.name != null)
                return false;
        } else if (!name.equals(other.name))
            return false;
        if (owner == null) {
            if (other.owner != null)
                return false;
        } else if (!owner.equals(other.owner))
            return false;
        if (size != other.size)
            return false;
        return true;
    }

    public boolean testEquals(String s1, String s2) {
        if (s1 == null && s2 == null || s1 != null && s2 != null && s1.equals(s2)) {
            return true;
        } else {
            return false;
        }
    }
}
